package com.study.it.xw.controller;

import com.study.it.xw.dao.CommentDao;
import com.study.it.xw.entity.Comment;
import com.study.it.xw.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
public class CommentController {
    @Autowired
    private CommentDao dao;
    @PostMapping("/comment/add")
    public String add(Comment comment, HttpSession session){
        User u=(User)session.getAttribute("user");
        comment.setUserId(u.getId());
        comment.setCreatetime(new Date());
        dao.insertComment(comment);
        //新增评论后，跳回该博文的明细页
        return "redirect:/detail?wbid="+comment.getWeiBoId();
    }
}
